<?php
html::printPath(array(
		'seminar.form-title' => 'admin/seminar/all',
		$seminar['name'] => '')
);
$msg->printMessages();

echo html::entityInfoIcon('seminar', $seminar, 'id');

if (! $seminar['active'] && ! date::isInPast($seminar['begin_date'])) {
    echo '<p class="warningNote">' . text::getEscaped('seminar.warning-notActive') . '</p> ';
}

echo '<div class="commandListFlow ui-helper-clearfix">';
echo '<ul class="commandList">';
// echo '<li class="editLi">' . html::anchor('admin/seminar/edit?id=' . $seminar['id'], text::get('seminar.editThis')) . '</li>';
if (! $seminar['active']) {
    echo '<li class="activateAction">' . html::anchor('admin/seminar/activate?id=' . $seminar['id'], text::get('seminar.activate')) . '</li>';
}
echo '<li class="translateAction">' . html::anchor('admin/seminarTranslation/listing?seminar_id=' . $seminar['id'], text::get('seminarTranslation.form-title')) . '</li>';
echo '<li class="receptionDeskAction">' . html::anchor('admin/receptionist/listing?seminar_id=' . $seminar['id'], text::get('seminar-receptionists')) . '</li>';
echo '<li class="registrationsLi">' . html::anchor('admin/registration/listing?seminar_id=' . $seminar['id'], text::get('seminar.registrationOverview')) . '</li>';
echo '</ul>';
echo '<ul class="commandList">';
echo '<li class="assignAccomodation">' . html::anchor('admin/seminarAccomodation/init?id=' . $seminar['id'], text::get('seminar-assignAccomodation'))  . '</li>';
echo '<li class="karmayogaAction">' . html::anchor('admin/karmayogaAssignment/init?seminar_id=' . $seminar['id'], text::get('seminar-karmayogaAssignment'))  . '</li>';
echo '<li class="billCommand">' . html::anchor('admin/seminarAccounts/init?seminarId=' . $seminar['id'], text::get('seminarAccounts-form-title')) . '</li>';
echo '<li class="paymentCommand">' . html::anchor('admin/seminarOrgPayment/listing?seminar_id=' . $seminar['id'], text::get('seminarOrgPayment-listing')) . '</li>';
echo '</ul>';
echo '<ul class="commandList">';
echo '<li class="policeAction">' . html::anchor('admin/seminar/exportForForeignPolice?id=' . $seminar['id'], text::get('seminar-exportForForeignPolice')) . '</li>';
echo '<li class="villageAction">' . html::anchor('admin/seminarVillageExport?id=' . $seminar['id'], text::get('seminar-villageFees')) . '</li>';
echo '</ul>';
echo '</div>';

/*----------------------------------------------------------------------------*/
// Basic info
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminarWizard.seminar-header') . '</h2>';

$fb = new FormBuilder('seminar', $seminar);
$fb->displayOnly();
$fb->setAction('/admin/seminarWizard/next');
$fb->text('name')->required();
$fb->textarea('description')->required();
$fb->spacer();
$fb->date('begin_date')->required();
$fb->time('begin_time')->required();
$fb->spacer();
$fb->date('end_date')->required();
$fb->time('end_time')->required();
$fb->spacer();
$fb->date('registration_deadline')->hint()->required();
$fb->yesNoBox('active')->noEmptyOption();
// $fb->textarea('notes');
$fb->write();

/*----------------------------------------------------------------------------*/
// Batches
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminarWizard.seminarBatch-header') . '</h2>';

$elb = new EntityListBuilder('seminarBatch', $batchList);
$elb->text('name')->noLink();
$elb->text('batch_type_code');
$elb->date('begin_date');
$elb->time('begin_time');
$elb->date('end_date');
$elb->time('end_time');
$elb->write();

/*----------------------------------------------------------------------------*/
// Price groups
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminarWizard.priceGroup-header') . '</h2>';

echo '<ul id="priceGroupList" class="wizardEntityList">';
foreach ($priceGroupList as $index => $group) {
    echo '<li>' .
         '<span style="font-weight: bold">' . $group['name'] . '</span>&nbsp;';
    echo '<div>';
    echo '<p>' . text::getEscaped('priceGroup.currency_code') . ': ' . $group['currency']['name'] . ' (' . $group['currency']['code'] . ')</p>';
    if ($group['countries']) {
        echo text::getEscaped('priceGroup.country_codes') . ': ';
        for ($i = 0; $i < count($group['countries']); $i++) {
            echo $group['countries'][$i]['name'] . ' (' . $group['countries'][$i]['code'] . ')';
            if ($i + 1 < count($group['countries'])) {
                echo ', ';
            }
        }
    }
    if ($group['description']) {
        echo '<p>' . text::getEscaped('priceGroup.description') . ': ' . $group['description'] . '</p>';
    }
    echo '</div>';
    echo '</li>';
}
echo '</ul>';

/*----------------------------------------------------------------------------*/
// Program types
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminarWizard.programType-header') . '</h2>';

$fb = new FormBuilder('seminarWizard', $programTypeForm);
$fb->displayOnly();
$fb->doNotCloseForm();
$fb->yesNoBox('satsang_available')->labelKey('seminarWizard.satsangEnabled')->noEmptyOption();
$fb->write();

if (count($programTypeList) > 0) {
    echo '<h3>' . text::getEscaped('seminarWizard.programTypeAvailability') . '</h3>';
    echo '<p class="description">' . text::getEscaped('seminarWizard.programTypeAvailability-desc') . '</p>';
    echo '<table class="programTypeBatchTable">';
    echo '<thead>';
    echo '<tr>';
    echo '<th></th>';
    foreach ($batchList as $batch) {
    	if ($batch['batch_type_code'] == constants::$singleDayBatchTypeCode) {
    		continue;
    	}
        echo '<th title="' . format::date($batch['begin_date']) . ' - ' . format::date($batch['end_date']) . '">' . $batch['name'] . '</th>';
    }
    // echo '<th></th>';
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    foreach ($programTypeList as $programType) {
        echo '<tr>';
        $onclick = 'checkOrUncheckAllInRow(this.parentNode.parentNode);';
        if ($programType['code'] == 'karmayoga') {
            $onclick .= 'toggleKarmayogaTypes(this.parentNode.parentNode)';
        }
        echo '<th><label class="textWithAction" onclick="' . $onclick . '" title="' . text::getEscaped('seminarWizard.clickToSelectAllBatchesOrNone') . '">' . $programType['name'] . '</label></th>';
        foreach ($batchList as $batch) {
	        if ($batch['batch_type_code'] == constants::$singleDayBatchTypeCode) {
	    		continue;
	    	}
            $batchCodesForThisProgramType = $programTypeBatchMap[$programType['code']];
            $checked = FALSE;
            if (is_array($batchCodesForThisProgramType)) {
                $checked = array_search($batch['batch_code'], $batchCodesForThisProgramType) !== FALSE;
            }
            echo '<td>' . ($checked ? 'x' : '') . '</td>';
        }
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
}

// Program types available in single day batches except satsang and co.
if ($singleDayProgramListWithoutShort) {
    echo '<h4>' . text::getEscaped('seminarWizard-singleDayBatchProgramTypes') . '</h4>';

    echo '<ul>';
    foreach ($singleDayProgramListWithoutShort as $programType) {
        echo '<li>' . $programType['name'] . '</li>';
    }
    echo '</ul>';
}

if ($karmayogaTypeList) {
    echo '<h3>' . text::getEscaped('seminarWizard.karmayogaTypes') . '</h3>';

    echo '<ul>';
    foreach ($karmayogaTypeList as $karmayogaType) {
        echo '<li>' . $karmayogaType['name'] . '</li>';
    }
    echo '</ul>';
}

echo '<h3>' . text::getEscaped('seminarWizard.availableExerciseGroups') . '</h3>';

if ($exerciseGroupList) {
    echo '<ul>';
    foreach ($exerciseGroupList as $exerciseGroup) {
        echo '<li>' . $exerciseGroup['name'] . '</li>';
    }
    echo '</ul>';
}

/*----------------------------------------------------------------------------*/
// Accomodation types
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminarWizard.accomodationType-header') . '</h2>';
?>

<table class="pricesTable">
    <thead>
        <tr>
            <th></th>
            <?php
            foreach ($batchList as $batch) {
                echo '<th>' . $batch['name'] . '<br/>' . format::date($batch['begin_date']) . ' - ' . format::date($batch['end_date']) . '</th>';
            }
            ?>
        </tr>
    </thead>
    <tbody>
        <?php
        $rowNumber = 1;
        foreach ($accomodationTypeList as $accomodationType) {
            echo '<tr' . ($rowNumber % 2 == 1 ? ' class="oddRow"' : '') . '>';
            echo '<th><span class="textWithAction" onclick="checkOrUncheckAllInRow(this.parentNode.parentNode)" title="' . text::getEscaped('seminarWizard.clickToSelectAllBatchesOrNone') . '">' . $accomodationType['name'] . '<span></th>';
            foreach ($batchList as $batch) {
                echo '<td>';
                $batchCodes = $accomodationTypeBatchMap[$accomodationType['code']];
                if ($batchCodes && (array_search($batch['batch_code'], $batchCodes) !== FALSE)) {
                    echo 'x';
                }
                echo '</td>';
            }
            echo '</tr>';
            $rowNumber ++;
        }
        ?>
    </tbody>
</table>

<?php
/*----------------------------------------------------------------------------*/
// Discounts
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminar.discounts') . '</h2>';
?>
<ul class="discountList">

    <!-- Discount for weak social groups -->
    <?php if ($socialDiscount) { ?>
        <li>
            <em class="textWithAction"><?php echo text::getEscaped('seminar.socialDiscount') ?></em>
            <p class="description"><?php echo text::getEscaped('seminar.socialDiscount-desc') ?></p>
            <table class="displayTable">
                <tbody>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.discountBeforeDeadlineOnly') ?></th>
                        <td><?php echo format::boolean($socialDiscount['before_deadline_only']) ?></td>
                    </tr>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.discountAvailableForKarmayoga') ?></th>
                        <td><?php echo format::boolean($socialDiscount['available_for_karmayoga']) ?></td>
                    </tr>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.discountHeightPercentage') ?></th>
                        <td><?php echo $socialDiscount['percentage'] ?> %</td>
                    </tr>
                </tbody>
            </table>
        </li>
    <?php } ?>

    <!-- Early registration discount -->
    <?php if ($earlyDiscount) { ?>
        <li>
            <em class="textWithAction"><?php echo text::getEscaped('seminar.earlyDiscount') ?></em>
            <p class="description"><?php echo text::getEscaped('seminar.earlyDiscount-desc') ?></p>
            <table class="displayTable">
                <tbody>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.chargeAppliesToKarmayoga') ?></th>
                        <td><?php echo format::boolean($earlyDiscount['applies_to_karmayoga']) ?></td>
                    </tr>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.earlyDiscountPercentage') ?></th>
                        <td><?php echo $earlyDiscount['percentage'] ?> %</td>
                    </tr>
                </tbody>
            </table>

        </li>
    <?php } ?>
</ul>

<?php
/*----------------------------------------------------------------------------*/
// Extra charges
/*----------------------------------------------------------------------------*/

echo '<h2>' . text::getEscaped('seminar.extraCharges') . '</h2>';
?>
<ul class="discountList">

    <!-- Cancellation charges -->
    <?php if ($cancellationCharge) { ?>
        <li style="margin-top: 24px;">
            <em class="textWithAction"><?php echo text::getEscaped('seminar.cancellationCharge') ?></em>
            <p class="description"><?php echo text::getEscaped('seminar.cancellationCharge-desc') ?></p>
            <table class="displayTable">
                <tbody>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.chargeAppliesToKarmayoga') ?></th>
                        <td><?php echo format::boolean($cancellationCharge['applies_to_karmayoga']) ?></td>
                    </tr>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.cancellationChargeBeforeDeadline') ?></th>
                        <td><?php echo $cancellationCharge['percentage_before_deadline'] ?> %</td>
                    </tr>
                    <tr>
                        <th><?php echo text::getEscaped('seminar.cancellationChargeAfterDeadline') ?></th>
                        <td><?php echo $cancellationCharge['percentage_after_deadline'] ?> %</td>
                    </tr>
                </tbody>
            </table>
        </li>
    <?php } ?>
</ul>